﻿@using Property;
@{
    ViewBag.Title = "NatureIndex";
}
@model string
@section head
{
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
    <link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-groupview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/plugins/datagrid-detailview.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/iconfont.css")" rel="stylesheet" type="text/css" />
    <link href="@Url.Content("~/App_Themes/default/icons/iconcontent/demo.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/ScriptPlugin/ztree/js/jquery.ztree.core-3.5.js")" type="text/javascript"></script>
    <link href="@Url.Content("~/ScriptPlugin/ztree/css/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
}
<div style="float:left;width:190px;height:100%">
    <div class="content-bar-color" style="height:34px; line-height: 34px; text-align: center">
       性质类别
    </div>
    <div class="content-pannel-buttons" style="border-bottom:1px solid #cccccc">
        <a onclick="NatureTypeAdd()"><b class="p-icon-add">新增</b></a>
        <a onclick="NatureTypeEdit()"><b class="p-icon-edit">编辑</b></a>
    </div>
    <div style="padding-top:1px">
        <ul id="tree" class="ztree"></ul>
    </div>
</div>
<div style="position:absolute;left:190px;right:0;height:100%">
    <div id="grid-bundles">
        <div id="toolpannel">
            <div class="content-pannel-buttons">
                <a><b class="p-icon-reload">刷新 </b></a>
                @if (ViewBag.createNaturegarent)
                {
                    <a onclick="NatureAdd()">
                        <b class="p-icon-add">
                            新增
                        </b>
                    </a>
                }
                @if (ViewBag.updateNaturegarent)
                {
                    <a onclick="rowEdit()"><b class="p-icon-edit">编辑</b></a>
                }
              @if (ViewBag.deleteNaturegarent)
              {
                <a onclick="rowDelete()"><b class="p-icon-delete">删除</b></a>
              }
              
                <a onclick="$('#grid-bundles').datagrid('load')">
                    <b class="p-icon-serch">查询</b>
                </a><a onclick="showicon()"> <b class="p-icon-clear">清空</b></a>
            </div>
            <div class="datagrid-filter-pannel" id="filterpannel">
                <table class="content-table-serch">
                    <tr>
                        <th>
                            性质内容
                            <input type="hidden" data-filter="true" id="Type" name="Type" />
                            <input type="hidden" data-filter="true" id="NatureCatalogId" name="NatureCatalogId" />
                        </th>
                        <td>
                            <input type="text" name="Value" data-filter="true" />
                            <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                                        height: 22px; float: left">@Html.GetFilterItem("Value", typeof(string))</a>
                                    </td>
                                    <th>
                                        排序号
                                    </th>
                                    <td>
                                        <input type="text" name="Order" data-filter="true" />
                                        <a class="p-icon-filter p-icon-filter-style" style="display: block; width: 22px;
                                        height: 22px; float: left">@Html.GetFilterItem("Order", typeof(int))</a>
                                    </td>
                                    <th>

                                    </th>
                                    <td></td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            @section foot
{
                <script type="text/javascript">
                    var jsonTree = @MvcHtmlString.Create(Model);
                    var settings = { callback: { onClick: nodeClick } };
                    var zTree = $.fn.zTree.init($("#tree"), settings, jsonTree);

                    function nodeClick(e,treeId, treeNode)
                    {
                        $("#NatureCatalogId").val(treeNode.id);
                        $("#grid-bundles").datagrid("load");
                    }
                    function NatureTypeAdd()
                    {
                        K.layer.iframe({
                            title: "@Html.GetLayerTitle(LayerIcon.Add,"新增字典类别")",
                            initfull: true,
                            maxmin: true,
                            btn: ["保存", "返回"],
                            content: "@Url.Content("~/Customer/Nature/NatureTypeAdd")",
                            area: ["480px", "340px"],
                            callback: function (result) {
                                if(K.ShowOrAlert(result)){
                                    loadNatureTypeTree();
                                    $("#grid-bundles").datagrid("load");
                                }
                            }
                        });
                    }
                    function NatureTypeEdit()
                    {
                        var nodes = zTree.getSelectedNodes();
                        if(nodes.length>0)
                        {
                            K.layer.iframe({
                                title: "@Html.GetLayerTitle(LayerIcon.Edit,"编辑字典类别")",
                                initfull: true,
                                maxmin: true,
                                btn: ["保存", "返回"],
                                content: "@Url.Content("~/Customer/Nature/NatureTypeEdit")?CatalogId=" + nodes[0].id,
                                area: ["480px", "340px"],
                                callback: function (result) {
                                    if (K.ShowOrAlert(result)) {
                                        loadNatureTypeTree();
                                    }
                                }
                            });
                        }
                        else
                        {
                            KingsSharp.Alert("请选择需要编辑的目录节点，根目录无法编辑");
                        }
                    }

                    function NatureAdd()
                    {
                        K.layer.iframe({
                            title: "@Html.GetLayerTitle(LayerIcon.Add,"新增字典")",
                            initfull: true,
                            maxmin: true,
                            btn: ["保存", "返回"],
                            content: "@Url.Content("~/Customer/Nature/NatureAdd")",
                            area: ["480px", "440px"],
                            callback: function (result,dto) {
                                if (K.ShowOrAlert(result)) {
                                    var dtoobject=JSON.parse(dto);
                                    $("#Parent\\.Id").val(dtoobject.Pid);
                                    var treeObj= $.fn.zTree.getZTreeObj("tree");
                                    var node = treeObj.getNodeByParam("id", dtoobject.Pid);
                                    treeObj.selectNode(node);
                                    $("#grid-bundles").datagrid("load");
                                }
                            }
                        });
                    }

                    function NatureEdit(id)
                    {
                        K.layer.iframe({
                            title: "@Html.GetLayerTitle(LayerIcon.Edit,"编辑字典")",
                            initfull: true,
                            maxmin: true,
                            btn: ["保存", "返回"],
                            content: "@Url.Content("~/Customer/Nature/NatureEdit")?NatureId=" + id,
                            area: ["480px", "445px"],
                            callback: function (result,dto) {
                                if (K.ShowOrAlert(result)) {
                                    var dtoobject=JSON.parse(dto);
                                    $("#Parent\\.Id").val(dtoobject.Pid);
                                    var treeObj= $.fn.zTree.getZTreeObj("tree");
                                    var node = treeObj.getNodeByParam("id", dtoobject.Pid);
                                    treeObj.selectNode(node);
                                    $("#grid-bundles").datagrid("load");
                                }
                            }
                        });
                    }

                    function rowEdit()
                    {
                        var row = $("#grid-bundles").datagrid('getSelected');
                        if (row != null)
                        {
                            NatureEdit(row.Id);
                        }
                        else
                        {
                            KingsSharp.Alert("请选中需要编辑的行");
                        }
                    }
                    function NatureDelete(rows)
                    {
                        var ids=[];
                        for(var i=0;i<rows.length;i++)
                        {
                            ids.push(rows[i].Id);
                        }
                        KingsSharp.Confirm("确认删除字典["+rows[0].Value+"]...等"+rows.length+"条数据？",function(){
                            KingsSharp.AjaxJson("@Url.Content("~/Customer/Nature/NatureRemove")",{deleteids:ids},function(result){
                                if(KingsSharp.ShowOrAlert(result)){
                                    $("#grid-bundles").datagrid("load");
                                }
                            });
                        })
                    }
                    function rowDelete()
                    {
                        var rows = $("#grid-bundles").datagrid('getChecked');
                        if (rows != null && rows.length>0)
                        {
                            NatureDelete(rows);
                        }
                        else
                        {
                            KingsSharp.Alert("请选中需要删除的行");
                        }
                    }

                    function loadNatureTypeTree()
                    {
                        KingsSharp.AjaxJson("@Url.Content("~/Customer/Nature/GetNatureTypeTree")",null,function(treedata){
                            if(typeof(treedata)=="string")
                            {
                                jsonTree=JSON.parse(treedata);
                            }
                            else
                            {
                                jsonTree=treedata;
                            }
                            zTree = $.fn.zTree.init($("#tree"), settings, jsonTree);
                        });
                    }

                    function LoadGridData()
                    {
                        var columns = [[
                            { field: "ck", checkbox: true},
                            { field: "Value", title: "性质内容", width: 180, sortable: true,formatter:function(val,row,index){
                                return "<a onclick=\"NatureEdit('" + row.Id + "')\">" + val + "</a>";
                            }},
                            { field: "Description", title: "性质说明", width: 400},
                            { field: "NatureCatalogName", title: "性质名称"},
                            { field: "Order", title: "排序", width: 40, sortable: true, halign: "center", align: "center" }
                        ]];
                        var parameter = {
                            title: "@Html.GetGridTitle("系统管理","顾客性质")",
                            columns: columns,
                            url: "@Url.Content("~/Customer/Nature/GetNatureGridData")",
                            pageNumber: 1,
                            DblClickRow: rowEdit
                        };
                        var grid= KingsSharp.GetGridData("#grid-bundles",parameter).Grid;
                    }
                    LoadGridData();
                </script>
            }


